var t = require("../../../../@babel/runtime/helpers/createForOfIteratorHelper"),
  e = require("../../../../@babel/runtime/helpers/objectSpread2"),
  a = require("../core");
Component((0, a.formItem)()({
  externalClasses: ["upload-class"],
  properties: {
    entryId: {
      type: Number
    },
    count: {
      type: Number,
      value: 6
    },
    max: {
      type: Number,
      value: 6
    }
  },
  data: {
    uploadList: [],
    tempFileList: [],
    updateType: ""
  },
  observers: {
    uploadList: function (t) {
      this.onChange(t), this.data.updateType = "onChange"
    },
    value: function (t) {
      "onChange" !== this.data.updateType && (t.forEach((function (t) {
        t.status || (t.status = "fulfilled")
      })), this.setData({
        tempFileList: t,
        uploadList: t
      }))
    }
  },
  methods: {
    replaceFile: function (t, a) {
      return t.map((function (t) {
        return t.id === a.id ? e(e({}, a), {}, {
          url: t.url
        }) : t
      }))
    },
    tempFilechange: function (e) {
      var a, i = this.data.tempFileList.concat(e.detail),
        l = [],
        r = t(i);
      try {
        for (r.s(); !(a = r.n()).done;) {
          var s, n = a.value,
            u = !0,
            o = t(l);
          try {
            for (o.s(); !(s = o.n()).done;) {
              var p = s.value;
              n.id === p.id && (u = !1)
            }
          } catch (t) {
            o.e(t)
          } finally {
            o.f()
          }
          u && l.push(n)
        }
      } catch (t) {
        r.e(t)
      } finally {
        r.f()
      }
      this.setData({
        tempFileList: l
      })
    },
    handleProgressUpdate: function (t) {
      this.setData({
        tempFileList: this.replaceFile(this.data.tempFileList, t.detail)
      })
    },
    handleUploadSuccess: function (t) {
      var e = this.data.uploadList.concat(t.detail),
        a = e.length - this.data.max,
        i = a >= 0 ? a : 0,
        l = e.slice(i, e.length);
      this.setData({
        uploadList: l
      }), this.setData({
        tempFileList: this.replaceFile(this.data.tempFileList, t.detail)
      })
    },
    handleUploadFail: function (t) {
      this.setData({
        tempFileList: this.replaceFile(this.data.tempFileList, t.detail)
      })
    },
    reUpload: function (t) {
      var e = this.selectComponent("#upload"),
        a = t.currentTarget.dataset.fileobj;
      e.reUpload(a)
    },
    handleDeleteFile: function (t) {
      var e = t.currentTarget.dataset.fileobj;
      this.setData({
        uploadList: this.data.uploadList.filter((function (t) {
          return t.url !== e.url
        }))
      }), this.setData({
        tempFileList: this.data.tempFileList.filter((function (t) {
          return t.url !== e.url
        }))
      })
      console.log(this.data.uploadList)
      console.log(this.data.tempFileList)
    },
    previewMedia: function (t) {
      var e = t.currentTarget.dataset.fileobj,
        a = 0,
        i = this.data.tempFileList.map((function (t, i) {
          return t.url === e.url && (a = i), {
            url: t.url,
            type: "image"
          }
        }));
      wx.previewMedia({
        sources: i,
        current: a
      })
    }
  }
}));